<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

//商品类型控制器
class Goodstype extends Admin_Controller{
	public function __construct(){
		parent::__construct();
		$this->load->model('admin/goodstype_model');
        $this->load->library('form_validation');
	}

	public function index(){

		$data['goodstypes'] = $this->goodstype_model->page_goodstype();
		$this->load->view('goods_type_list.html',$data);
	}



	#添加商品类型
	public function insert()
    {
        #设置验证规则
        $this->form_validation->set_rules('type_name', '商品类型名称', 'trim|required');

        if ($this->form_validation->run() == false) {
            # code...
            $data['message'] = validation_errors();
            $data['wait'] = 5;
            $data['url'] = base_url() . 'admin/goodstype/index';
            $this->load->view('message.html', $data);
        } else {
            # code...
            $data['type_name'] = $this->input->post('type_name', true);

            if ($this->goodstype_model->add_goodstype($data)) {
                $data['message'] = '添加商品类型成功';
                $data['wait'] = 5;
                $data['url'] = base_url() . 'admin/goodstype/index';
                $this->load->view('message.html', $data);
            } else {
                # code...
                $data['message'] = '添加商品类型失败';
                $data['wait'] = 5;
                $data['url'] = base_url() . 'admin/goodstype/index';
                $this->load->view('message.html', $data);
            }

        }
    }
}